// Get Query String as key/value pairs
function getParams() {
    var params = {};
    var pairs = location.search.substring(1).split("&");
    for (var i = 0; i < pairs.length; i++) {
	var pair = pairs[i].split("=");
	params[pair[0]] = pair[1];
    }
    return params;
}

// Get Cookies as key/value pairs
function getCookies() {
    var cookies = {};
    if (!navigator.cookieEnabled)
	return;
    var pairs = document.cookie.split("; ");
    for (var i = 0; i < pairs.length; i++) {
	var pair = pairs[i].split("=");
	cookies[pair[0]] = pair[1];
    }
    return cookies;
}

// Set session-only cookie
function setCookie(name, value) {
    var cookie = name + "=" + escape(value);
    document.cookie = cookie;
}

// Set permanent cookie
function setPermanentCookie(name, value, expires, domain, path, secure) {
    var cookie = name + "=" + escape(value) +
	(expires) ? "; expires=" + expires.toGMTString() : "" +
	(domain)  ? "; domain="  + domain : "" +
	(path)    ? "; path="    + path : "" +
	(secure)  ? "; secure" : "";
    document.cookie = cookie;
}
